
<template>
  <div>
    <el-row>
      <mu-appbar title="领取礼品码记录" style="background-color:#409EFF">
        <mu-icon-button  icon="arrow_back_ios" slot="left" :to="{name: 'CodeMenu' }"/>
      </mu-appbar>
    </el-row>

    <el-row style="margin-top:16px;">
      <el-col :xs="6" :sm="4" :md="3" :lg="3">
        领取ID
      </el-col>
      <el-col :xs="18" :sm="20" :md="21" :lg="21">
        <el-input v-model="condition.accountId" size="mini" @blur="getUseCodeDetail"></el-input>
      </el-col>
    </el-row>

    <el-table
      :data="tableData"
      style="width: 100%">
      <el-table-column
        prop="useAccountId"
        label="领取ID">
      </el-table-column>
      <el-table-column
        prop="wechat"
        label="领取昵称">
      </el-table-column>
      <el-table-column
        prop="ndot"
        label="领取金币">
        <template slot-scope="scope">
          <span>{{scope.row.ndot}}个</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="code"
        label="使用礼品码">
      </el-table-column>
      <el-table-column
        prop="useTime"
        label="领取时间">
      </el-table-column>
    </el-table>

    <el-row>
      <center>
        <el-pagination
          small
          layout="prev, pager, next"
          :total="condition.total"
          :page-size="condition.pageSize"
          :current-page="condition.currentPage"
          @current-change="handleCurrentChange">
        </el-pagination>
      </center>
    </el-row>

</div>
</template>

<script>
  import moment from 'moment'
  export default {
    data () {
      return {
        tableData: [],
        condition: {
          accountId: '',
          startDay: '',
          endDay: '',
          currentPage: 1,
          pageSize: 20,
          total: 0,
          account: sessionStorage.getItem('account')
        }
      }
    },
    methods: {
      getUseCodeDetail () {
        let that = this
        if (this.condition.accountId === '' || this.condition.accountId.length === 0) {
          this.condition.accountId = -1
        }
        this.$axios({
          method: 'get',
          url: '/api/CarrieroperatorService.useCodeDetail',
          params: this.condition
        })
        .then(function (resp) {
          if (resp.data.status === 'success') {
            for (let item in resp.data.data) {
              resp.data.data[item].useTime = moment.utc(resp.data.data[item].useTime).zone(-8).format('YYYY-MM-DD HH:mm:ss')
            }
            that.tableData = resp.data.data
            that.condition.total = resp.data.page.total
            if (that.condition.accountId === -1) {
              that.condition.accountId = ''
            }

          } else {
            that.$message({
              showClose: true,
              message: resp.data.cause,
              type: 'warning'
            })
          }
        })
      },
      init () {
        this.getUseCodeDetail()
      },
      handleCurrentChange (val) {
        this.condition.currentPage = val
        this.getUseCodeDetail()
      }
    },
    mounted () {
      this.init()
    }
  }
</script>
